Repository navigation
Conversation
LeanBitLab
left a comment
There was a problem hiding this comment.
Thanks for this. Keeping a custom key result when the editor hides the keyboard is useful, but the PR changes more than custom keys. A few regressions and risks before we can merge:
1. Proofread and translate are no longer cancelled when the keyboard hides (regression)
ProofreadHelper.cancelCurrentJob() is removed from both onWindowHidden and onFinishInputView. That also applies to proofread and translate, but their onSuccess still drops the result when the input view is hidden. So:
- the request runs to the end for nothing (a paid cloud API call, or minutes of CPU on the offline model),
- the loading border is still there when the keyboard comes back, possibly in another app,
- the first tap on proofread in the new field only cancels the old request (with #890, translate and the custom keys do the same),
cancelCurrentJob()becomes dead code in both flavors.
Please keep the cancel on hide and skip it only while a custom key request runs. For example, ProofreadHelper could remember whether the running job was started by customAsync (cancelCurrentJob(keepCustomKeyJob = true)), so proofread and translate keep their current behaviour.
2. Typing during the request now sends the result to the clipboard (behaviour change with the keyboard open)
targetField.isCurrent() now also runs while the keyboard stays open. If the user keeps typing in the same field while waiting, the text no longer matches and the result goes to the clipboard. For #append this is a regression: before, the result was appended. Please keep the existing package/field id check for the normal path and use the text fingerprint only for a result that arrived while the keyboard was hidden (the case this PR is about).
3. Extra reads of the whole field on the main thread
currentAiTarget() reads up to 60k characters before and after the cursor plus getExtractedText (hint 120k chars) right after handleCustomAIKey has already read the same text, and again when the result arrives. In big fields or slow web editors that is several large IPC calls on the main thread. Suggestions:
- build the request snapshot from the text already read for
textToProcess, - only call
getExtractedTextwhen the first comparison fails.
4. A cancelled request still generates after waiting for generateLock (offline)
A request that was cancelled while it waited for the lock still runs a full generation once it gets the lock, because the plugin call can't be interrupted. Please check coroutineContext.isActive after taking the lock and skip provider.generate for a cancelled request.
5. Minor
mPendingAIResultshould be cleared when a new AI request starts, so an old result can't be inserted after a newer one.onFinishInputViewruns on every field switch, so with (1) fixed this mostly goes away, but please test switching fields during a request in a chat app (same field id for every chat).
To keep #888 and #890 easy to merge, please keep the changes inside handleCustomAIKey, AiFieldCheck and ProofreadHelper, and leave the prompt building in ProofreadService (touched by #888) and the toolbar loading code in SuggestionStripView (touched by #890) as they are.
LeanBitLab
left a comment
There was a problem hiding this comment.
Marking as changes requested: please address the regression and risks in my review comment above (mainly: keep cancelling proofread/translate when the keyboard hides, and keep the old insert behaviour while the keyboard stays open).
…ly into the same field Some editors hide the keyboard while a custom AI key runs (they react to the cursor being moved for the result). The request was cancelled and the result lost. Now a custom key request keeps running when the keyboard hides (proofread and translate are still cancelled), and a result that arrives meanwhile is inserted when the keyboard is back in the same field within two minutes. Many apps use the same field id for all their text fields (e.g. every chat). So a kept result, or a result after another field was opened meanwhile, is only inserted if the app, input type and text of the field are the same as when the request was made (from the text already read for the request; the text the app gives for extraction is only read if the first comparison fails), never in a password field. Otherwise it is copied to the clipboard with a short message. While the keyboard stays in the same field, the behaviour is as before. Offline AI: one generation at a time. The plugin can't stop a running generation, and a new request failed with "Context is busy". It now waits for the previous one, and is skipped if it was cancelled while waiting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VuiaMhLXwhErf9shhrr1uD
509bc75 to
583d1b3
Compare
- Proofread and translate are cancelled again when the keyboard hides (their result is dropped then anyway); only a custom key request keeps running. - Appending with a custom key while typing on in the same field works again; the field check is used after another field was opened, and for replacing. - A new custom key request drops an older kept result; a kept result is not inserted while a newer request runs. - Offline: a request cancelled while waiting for the previous generation does not start one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VuiaMhLXwhErf9shhrr1uD
|
Thanks for the careful review! All points are addressed in the updated branch (one commit, force-pushed):
The changes stay in Tested on my phone: switching to another chat during a custom key request puts the result into the clipboard instead of the other chat, and appending while typing on in the same field works as before. |
Some editors hide the keyboard while a custom AI key is running, e.g. because they react to the cursor being moved for the result (seen in Nine Mail). The request was cancelled and the result was lost.
The field check is a small class with unit tests (
AiFieldCheckTest). In daily use in my fork since end of October.🤖 Generated with Claude Code